#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

'''
文件名称：main.py
创 建 者：yang qiang
创建日期：2021年02月21日
描    述：
Copyright (C) 2021 All rights reserved.
'''

class Solution:
    def __init__(self):
        self.res = list()

    def Permutation(self, ss):
        # write code here
        if len(ss) > 0:
            strlist = list(ss)
            self.PermutationHelper(strlist, 0)
            self.res.sort()

        return self.res

    def swap(self, l, i, j):
        tmp = l[i]
        l[i] = l[j]
        l[j] = tmp

    def PermutationHelper(self, strlist, begin):
        if begin == len(strlist) - 1:
            s = ''.join(strlist)
            if s not in self.res:
                self.res.append(s)

            return

        for i in range(begin, len(strlist)):
            self.swap(strlist, begin, i)
            self.PermutationHelper(strlist[:], begin + 1)
            self.swap(strlist, begin, i)
